#include "Camera.h"

Camera::Camera()
{
	cameraPosition = D3DXVECTOR3(0.0f,0.0f,-100.0f);
	lookAt = D3DXVECTOR3(0.0f,0.0f,1.0f);
	realLookAt = D3DXVECTOR3(0.0f,0.0f,0.0f);
	rotation = D3DXVECTOR3(0.0f,0.0f,0.0f);
	up = D3DXVECTOR3(0.0f,1.0f,0.0f);
}
Camera::Camera(D3DXVECTOR3 _cameraPosition)
{
	cameraPosition = _cameraPosition;
	lookAt = D3DXVECTOR3(0.0f,0.0f,1.0f);
	realLookAt = D3DXVECTOR3(0.0f,0.0f,0.0f);
	rotation = D3DXVECTOR3(0.0f,0.0f,0.0f);
	up = D3DXVECTOR3(0.0f,1.0f,0.0f);
}
void Camera::rotate(D3DXVECTOR3 _angle)
{
	rotation += _angle;
	D3DXMATRIX matRotate;
	D3DXMatrixRotationYawPitchRoll(&matRotate,D3DXToRadian(rotation.y),D3DXToRadian(rotation.x),D3DXToRadian(rotation.z));
	D3DXVECTOR4 v4rotation;
	D3DXVec3Transform(&v4rotation,&lookAt,&matRotate);
	
	realLookAt = (D3DXVECTOR3)v4rotation;

	D3DXVECTOR4 v4up;
	D3DXVec3Transform(&v4up,&up,&matRotate);
	realUp = (D3DXVECTOR3)v4up;
}
void Camera::setCameraPosition(D3DXVECTOR3 _cameraPosition)
{
	cameraPosition = _cameraPosition;
}
void Camera::setLookPosition(D3DXVECTOR3 _lookAt)
{
	lookAt = _lookAt;
}
void Camera::setUp(D3DXVECTOR3 _up)
{
	up = _up;
}
void Camera::render(LPDIRECT3DDEVICE9 _d3ddev)
{

	D3DXMATRIX matView;	
	
	//D3DXVECTOR3 finalLookAt = cameraPosition+realLookAt;
	D3DXVECTOR3 finalLookAt = D3DXVECTOR3(0,0,0);//cameraPosition+lookAt;
	D3DXMatrixLookAtLH(&matView,&cameraPosition,
								&finalLookAt,
								&realUp);
	_d3ddev->SetTransform(D3DTS_VIEW,&matView);
}
void Camera::moveForward(float _speed)
{
	cameraPosition += realLookAt*_speed;
}
D3DXVECTOR3 Camera::getCameraPosition()
{
	return cameraPosition;
}
D3DXVECTOR3 Camera::getLookPosition()
{
	return realLookAt;
}
D3DXVECTOR3 Camera::getUp()
{
	return up;
}
D3DXVECTOR3 Camera::getRotation()
{
	return rotation;
}